import { Component } from "react";
import { Button, Image, Input, Toast, Space } from 'antd-mobile'
import style from "./login.module.css"
import { logins } from "../apis/login";
import { Link } from "react-router-dom";
export default class Login extends Component {
    state = {
        demoSrc2: 'https://images.unsplash.com/photo-1493666438817-866a91353ca9?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&fit=crop&h=200&w=200&s=b616b2c5b373a80ffc9636ba24f7a4a9',
        username: "",
        pwd: "",
        icon:"",
        num:2,
    }
    render() {
        return (
            <>
                <Image src={this.state.demoSrc2} className={style.img} />
                <div className={style.center}>
                    <div className={style.title}>前端电影院</div>
                    <form action="" className={style.form}>
                        <div className="input-div">
                            账号：<input type={"text"} onChange={this.userChange} />
                        </div>
                        <div className="input-div">
                            密码：<input type={"password"} onChange={this.pwdChange} />
                        </div>
                    </form>
                    <Space wrap className={style.reg}>
                        <Link to="/reg">注册</Link>
                        <span>忘记密码?</span>
                    </Space>
                    <Space wrap className={style.btn}>
                        <Button block color='primary' size="large" onClick={this.loginChange} >登录</Button>
                    </Space>
                </div>
            </>
        )
    }
    userChange = (e) => {
        this.setState({ username: e.target.value })
        // console.log(e.target.value);
    }
    pwdChange = (e) => {
        this.setState({ pwd: e.target.value })
        // console.log(e.target.value);
    }
    loginChange=async()=>{
        let res=await logins({
            acc:this.state.username,
            pwd:this.state.pwd
        })
        // console.log(res);
        if (res.data.code=="1") {
            window.location.href='/#/nav'
            Toast.show({
                icon: 'success',
                content: '登录成功',
            })
            localStorage.setItem('islogin',1);
        } else {
            Toast.show({
                icon: 'fail',
                content: '登录失败',
            })
        }

    }

    // loginChange = () => {
    //     // console.log(this.state.username);
    //     if (this.state.username == "admin" && this.state.pwd == "12345") {
    //         Toast.show({
    //             icon: 'success',
    //             content: '登录成功',
    //         })
    //     } else {
    //         Toast.show({
    //             icon: 'fail',
    //             content: '登录失败',
    //         })
    //     }
    // }


    // loginChange=()=>{
    //     axios({
    //         methods:"get",
    //         url:"http://129.211.169.131:3333/searchMovieList",
    //         params:{
    //             state:2
    //             // pwd: 
    //         }
    //     }).then((res)=>{
    //         console.log(res);
    //     })
    // }
}